﻿<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>数据字典</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
	<span class="c-gray en">&gt;</span>
	系统管理
	<span class="c-gray en">&gt;</span>
	数据字典
	<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<div class="page-container">
		<div class="text-c">字典名称:
			<input type="text" class="input-text" id="systemDictionaryName" name="" style="width:150px">
			分类名:
			<span class="select-box inline">
		<select class="select" id="selectAdd" name="systemDictionaryType">
			<option value="">选择一个系统分类</option>
		</select>
		</span>
			排序值:
			<input type="number" class="input-text" id="systemDictionarySequence" style="width:150px">
			<button type="submit" class="btn btn-primary radius" id="addSystemDictionary" ><i class="Hui-iconfont">&#xe600;</i> 添加字典</button>
		</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20 text-c">
		<span class="l">
		<a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
		</span>
		分类名:
		<span class="select-box inline">
		<select class="select" id="select">
			<option value="">选择一个系统分类</option>
		</select>
		</span>
		&nbsp;&nbsp;&nbsp;
		<input type="text" id="criteria" placeholder="id、名称、分类、排序值" style="width:250px" class="input-text">
		<button id="search" class="btn btn-success" type="submit"><i class="Hui-iconfont"></i> 搜索</button>
		<span class="r">共有数据：<strong id="count">0</strong> 条</span>
	</div>
		<div class="mt-20">
			<div id="dataTables" class="dataTables_wrapper no-footer">
				<div class="dataTables_length" ><label>显示 <select id="pageSize" aria-controls="DataTables_Table_0" class="select"><option value="10">10</option><option value="25">25</option><option value="50">50</option><option value="100">100</option></select> 条</label></div>
				<table class="table table-border table-bordered table-bg table-hover table-sort">
					<thead>
					<tr class="text-c">
						<th width="25"><input type="checkbox" name="" value=""></th>
						<th width="80">ID</th>
						<th>名称</th>
						<th>字典分类</th>
						<th width="305">排序值</th>
						<th width="100">操作</th>
					</tr>
					</thead>
					<tbody class="text-c">
					<tr>
						<td><input type="checkbox" value="" name=""></td>
						<td>0001</td>
						<td>城市</td>
						<td>city</td>
						<td class="f-14"><a style="text-decoration:none" onclick="system_data_edit('角色编辑','system-data-edit.html','0001','400','310')" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>
							<a title="删除" href="javascript:;" onclick="system_data_del(this,'10001')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
					</tr>
					</tbody>
				</table>
				<div class="dataTables_info" id="DataTables_Table_0_info" role="status" aria-live="polite">显示 <span id="startRow">0</span> 到 <span id="endRow">0</span> ，共 <span id="total">0</span> 条</div>
			</div>
		</div>
	</div>
</div>
	<!--_footer 作为公共模版分离出去-->
	<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
	<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
	<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
	<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

	<!--请在下方写此页面业务相关的脚本-->
	<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
	<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
	<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
	<script type="text/javascript" src="js/util.js"></script>
	<script type="text/javascript">
		//存储当前页码
		var pageNum=1;

		//加载字典
		$.ajax({
			url:"allSystemDictionary",
			dataType:"json",
			type:"post",
			async:false,
			success:function(res){
				var data=res.data;
				if(data!=null){
				    var list=data.list;
				    for(var i =0;i<list.length;i++){
				        var html='<option value="'+list[i].id+'">'+list[i].title+'</option>';
				        $("#select").append(html);
				        $("#selectAdd").append(html);
					}
				}
			}
		})
		//添加字典明细
		$("#addSystemDictionary").click(function(){
			var name		= $("#systemDictionaryName").val();
			var parentId	= $("#selectAdd").val();
			var sequence	= $("#systemDictionarySequence").val();
			if(_util.isNull(name)){
			    layer.msg("添加的字典名称不能为空");
                $("#systemDictionaryName").focus();
			    return;
			}
			if(_util.isNull(parentId)){
			    layer.msg("请选择一个字典分类");
                $("#selectAdd").focus();
			    return;
			}
			if(sequence==null||sequence<=0){
			    layer.msg("排序值需大于0");
                $("#systemDictionaryName").focus();
			    return;
			}

			$.ajax({
				url:"addOrUpdateSystemDictionaryItem",
				data:{"title":name,"parentId":parentId,"sequence":sequence},
				dataType:"json",
				type:"POST",
				success:function(res){
					if(res.status===0){
                        $("#systemDictionaryName").val("");
                        $("#systemDictionarySequence").val("");
					    layer.msg("添加字典明细成功!");
                        DataTablesReloda();
					}
				}
			})
		})

        var id=null;
        var table	= $('.table-sort').dataTable({
            "aaSorting": [[ 1, "desc" ]],//默认第几个排序
            "bStateSave": true,//状态保存
            "lengthChange": false,//是否允许改变分页大小
            "paging": false,//是否开启本地分页
            "info": false,//是否显示左下角信息
            "aoColumnDefs": [
                //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                {"orderable":false,"aTargets":[0,4]}// 制定列不参与排序
            ],
            "ajax" : {
                url:"allSystemDictionaryItem",
                async:false,
                cache:false,
                type:"post",
                dataType:"json",
                dataSrc:function(data){//这是从服务器接受的数据（名称、格式）
					//没有数据的处理
                    if(data.data==null){
                        return 0;
                    }
                    $("#count").text(data.data.total);
                    $("#startRow").text(data.data.startRow);
                    $("#endRow").text(data.data.endRow);
                    $("#total").text(data.data.total);
                    //计算分页
                    $("#pageData").remove();//删除自己
                    if(data.data.pageNum<1){
                        data.data.pageNum=1;
                    }
                    var html='<div class="dataTables_paginate paging_simple_numbers" id="pageData">';
                    html+='<a class="paginate_button" data-dt-idx="'+(data.data.pageNum-1)+'">上一页</a>';
                    var length=data.data.navigatepageNums.length;
                    for(var i=1;i<=length;i++){
                        if(data.data.pageNum==i){
                            html+='<span><a class="paginate_button current"  data-dt-idx='+i+'>'+i+'</a></span>';
                        }else{
                            html+='<span><a class="paginate_button"  data-dt-idx='+i+'>'+i+'</a></span>';
                        }
                    }
                    html+='<a class="paginate_button"  data-dt-idx="'+data.data.nextPage+'">下一页</a>';
                    html+='</div>';
                    $("#dataTables").append(html);
                    //改变分页
                    $('.paginate_button').on('click', function() {
						pageNum=$(this).attr("data-dt-idx");
                        DataTablesReloda();
                    });
                    return data.data.list;
                }
            },
            "columns" : [
                {"data":null,
                    "render":function(data,type,row){
                        var html='<input type="checkbox" value="'+data.id+'" name="">';
                        return html;
                    }
                },
                {"data":"id"},
                {"data":"title"},
                {"data":"parentId",
					"render":function(data){
                    	return $("#select").find("option[value='"+data+"']").text();
					}
				},
                {"data":"sequence"},
                {"data":null,
                    "render":function(data,type,row){
                        var html="<a style='text-decoration:none' onclick=\"system_data_edit('字典明细编辑','change-systemdictionaryItem.html','"+data.id+"','400','310')\" href='javascript:;' title='编辑'><i class='Hui-iconfont'>&#xe6df;</i></a>";
                        html+="<a title='删除' href='javascript:;' onclick=\"system_data_del(this,'"+data.id+"')\" class='ml-5' style='text-decoration:none'><i class='Hui-iconfont'>&#xe6e2;</i></a>";
                        return html;
                    }
                }
            ]
        });
        //重新加载表格
        function DataTablesReloda(){
            table.api().settings()[0].ajax.data={"parentId":$("#select").val(),"criteria":$("#criteria").val(),"pageSize":$("#pageSize").val(),"pageNumber":pageNum};
            table.api().ajax.reload();
        }
        //搜索
        $("#search").click(function(){
            DataTablesReloda();
        })
        //页码被改变
        $("#pageSize").change(function(){
            DataTablesReloda();
        })
        //分类被改变
        $("#select").change(function(){
            DataTablesReloda();
        })
        /*数据字典-编辑*/
        function system_data_edit(title,url,ids,w,h){
            id=ids;
            layer_show(title,url,w,h,id);
        }

        /*数据字典-删除*/
        function system_data_del(obj,id){
            layer.confirm('确认要删除ID为:"'+id+'"的字典吗？',function(index){
                $.ajax({
                    type: 'POST',
                    url: 'delSystemDictionaryItem',
                    dataType: 'json',
                    data:{"id":id},
                    success: function(data){
                        DataTablesReloda();
                        layer.msg('已删除!',{icon:1,time:1000});
                    },
                    error:function(data) {
                        console.log(data.msg);
                    },
                });
            });
        }
	</script>
</body>
</html>